package
{
	import mx.formatters.Formatter;

	public class MyFormatter extends Formatter
	{
		public static const EARTH:String = "upperCase";
		public static const MOON:String = "lowerCase";
		public static const NUM:String = "myNumber";

		public var myFormtterString:String = EARTH;
		public var mask:String;

		public var seperator:String = "-";

		public function MyFormatter(mask:String="")
		{	
			this.mask = mask;
			super();
		}
		
		
		private function onInit():void{
			myTest(2,3);
			onInit();
		}
		
		private function myTest(a:int,b:int):int{
			return a+b;
		}

		// input: number: xxxxxxxx  8 digits 12345678   mask: xxx-xx-xxx
		// output: 123-45-678

//		override public function format(value:Object):String{
////			var resultStr:String = 
//			return "";
//		}		
		override public function format(value:Object):String{
			if( value.length == 0)
			{   error="invalid string";
				return ""
			}

			// If the value is valid, format the string.
			switch (myFormtterString) {
				case "upperCase" :
					var upperString:String = value.toUpperCase();
					return "[Earth:]"+upperString;
					break;
				case "lowerCase" :
					var lowerString:String = value.toLowerCase();
					return "[Moon:]"+lowerString; 
					break;
				case "myNumber":
					var count:int = 0;
					var s:String="";
					var temp:Array = new Array();
					for(var i:int=0;i<mask.length;i++){
						temp[i] = mask.charAt(i);
					}
					for(i=0;i<temp.length;i++){
						if( temp[i]== "x"){
							s += value.charAt(count);
							count++;
						}
						else{
							s+="-";
						}
					}
					return s;
					break;
					
				default :   
					error="Invalid Format String";
					return "";
			}
		}
	}
}

